package com.zodiac.app.szse.sse.kcb;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;

import java.util.TreeMap;

@NoArgsConstructor
@Data
public class KcbProjectDynamicRequest {
    private String jsonCallBack = "jsonCallBack" + RandomStringUtils.randomNumeric(5);
    private Boolean isPagination = true;
    private String sqlId = "SH_XM_LB";
    private String offerType;
    private String commitiResult;
    private String registeResult;
    private String csrcCode;
    private String currStatus;
    private String order = "updateDate%7Cdesc";
    private String keyword;
    private String auditApplyDateBegin;
    private String auditApplyDateEnd;
    private int pageHelp_pageSize = 100;
    private int pageHelp_pageNo = 1;
    private int pageHelp_beginPage = 1;
    private int pageHelp_endPage = 1;

    public KcbProjectDynamicRequest pageNo(int pageNo) {
        this.pageHelp_pageNo = pageNo;
        this.pageHelp_beginPage = pageNo;
        this.pageHelp_endPage = pageNo;
        return this;
    }

    public String toQueryString() {
        final TreeMap<String, Object> parameters = new TreeMap<>();
        final JSONObject conditions = JSON.parseObject(JSON.toJSONString(this));
        conditions.keySet().forEach(k -> parameters.put(k.replace("_", "."), conditions.get(k)));
        return Joiner.on("&").withKeyValueSeparator("=").join(parameters) + "&_=" + System.currentTimeMillis();
    }
}
